from rest_framework import serializers
from .models import *
from patient.models import *


class PatientPostSer(serializers.ModelSerializer):
    class Meta:
        model = Patient
        fields = ['name',
                  'gender',
                  'id_care',
                  'blood_type',
                  'data_birth',
                  'mobile',
                  # 'illness_desc',  # 病人病情描述
                  'diagnosis',  # 诊断结果
                  'diagnosis_instructions',  # 诊断说明
                  'medicine_choice',  # 选择用药
                  'family_mobile',  # 家属电话
                  'is_hospital',  # 建议是否住院
                  'department',  # 科室
                  'doctor',  # 医生
                  ]

    def create(self, validated_data):
        if validated_data.get('is_hospital'):
            name = validated_data.get('name')
            gender = validated_data.get('gender')
            data_birth = validated_data.get('data_birth')
            mobile = validated_data.get('mobile')
            id_care = validated_data.get('id_care')
            blood_type = validated_data.get('blood_type')
            family_mobile = validated_data.get('family_mobile')
            doctor = validated_data.get('doctor')
            department = validated_data.get('department')
            diagnosis = validated_data.get('diagnosis')

            result = Result.objects.create(result_content=diagnosis)
            patient_info = PatientInfo.objects.create(name=name,
                                                      gender=gender,
                                                      data_birth=data_birth,
                                                      mobile=mobile,
                                                      id_care=id_care,
                                                      blood_type=blood_type,
                                                      family_mobile=family_mobile,
                                                      doctor=doctor,
                                                      department=department,
                                                      result=result)
            print(patient_info)
        patient = Patient.objects.create(**validated_data)

        return patient


class PatientGetSer(serializers.ModelSerializer):
    class Meta:
        model = Patient
        fields = ['id',
                  'name',
                  'gender_name',
                  # 'id_care',
                  'blood_type_name',
                  'data_birth',
                  'mobile',
                  'illness_desc',  # 病人病情描述
                  'diagnosis',  # 诊断结果
                  'diagnosis_instructions',  # 诊断说明
                  'medicine_choice',  # 选择用药
                  'family_mobile',  # 家属电话
                  'is_hospital_name',  # 建议是否住院
                  'department_type_name',  # 科室分类名
                  'department_name',  # 科室名
                  'doctor_name',  # 医生
                  'state',
                  'state_name',
                  'cost',
                  ]
